home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / fpk65_66.zip / DEMO / DEMO.PP next >
Text File  |  1997-01-30  |  5KB  |  249 lines

  1. program testgraf;
  2.  
  3. uses crt,graph,hex;
  4.  
  5. var maxx,maxy : longint;
  6.     gd,gm     : integer;
  7.     MaxColors : Longint;
  8.     Drive     : String;
  9.  
  10. {$IFDEF TURBO}
  11. {$I STDCOLOR.PPI}
  12. {$ENDIF}
  13.  
  14. procedure Dummy;begin end;
  15.  
  16. function Int2Str(value:LongInt):String;
  17. var s:string;
  18. begin
  19.  str(value,s);
  20.  int2str:=s;
  21. end; 
  22.  
  23. procedure SetStandartColor(Nr:Integer);
  24. begin
  25.   nr:=nr and $ff;
  26.   if MaxColors>256 then SetColor(stdcolors[nr]) else SetColor(nr);
  27. end;
  28.  
  29. procedure SetStandartFillStyle(a:word;b:longint);
  30. begin
  31.   b:=b and $FF;
  32.   if MaxColors>256 then SetFillStyle(a,stdcolors[b]) else SetFillStyle(a,b);
  33. end;
  34.  
  35. procedure SetStandartFillPattern(a:FillPatternType;b:longint);
  36. begin
  37.   b:=b and $ff;
  38.   if MaxColors>256 then SetFillPattern(a,stdcolors[b]) else SetFillPattern(a,b);
  39. end;
  40.  
  41. procedure FullViewPort;
  42. begin
  43.   SetViewPort(0,0,maxx,maxy,ClipOn);
  44. end;
  45.  
  46. procedure MainWindow(Header:String);
  47. var h,i:Integer;
  48. begin
  49.   FullViewport;
  50.   ClearDevice;
  51.   h:=TextHeight('M');
  52.   SetTextStyle(defaultfont,HorizDir,1);
  53.   SetTextJustify(centertext,toptext);
  54.   SetStandartFillStyle(solidfill,blue);
  55.   SetStandartColor(white);
  56.   for i:=0 to h+10 do begin
  57.     setcolor((i shl 24)+$10000020+(i shl 3));
  58.     line(0,i,maxx,i);
  59.   end;
  60.   SetStandartcolor(white);
  61.   rectangle(0,0,maxx,maxy);
  62.   line(0,h+11,maxx,h+11);
  63.   OutTextXY(maxx shr 1,5,Header);
  64.   SetViewPort(1,h+12,maxx-1,maxy-1,clipon);
  65. end;
  66.   
  67. procedure RandomDots;
  68. var VP  : Viewporttype;
  69.     x,y : integer;
  70. begin
  71.   MainWindow('Randomdots');
  72.   GetViewSettings(VP);
  73.   with VP do begin
  74.     x:=x2-x1; y:=y2-y1;
  75.   end;
  76.   Randomize;
  77.   repeat
  78.     PutPixel(random(x),random(y),random(maxcolors));
  79.   until keypressed;
  80.   readkey;
  81. end;
  82.  
  83. procedure RandomCircle;
  84. var VP  : Viewporttype;
  85.     x,y : integer;
  86. begin
  87.   MainWindow('Randomcircles');
  88.   GetViewSettings(VP);
  89.   x:=VP.x2-VP.x1; y:=VP.y2-VP.y1;
  90.   Randomize;
  91.   repeat
  92.     SetStandartcolor(random(250)+1);
  93.     Circle(random(x),random(y),random(100));
  94.   until keypressed;
  95.   readkey;
  96. end;
  97.  
  98. procedure RandomArc;
  99. var VP  : Viewporttype;
  100.     x,y : integer;
  101.     count:integer;
  102. begin
  103.   MainWindow('RandomArcs');
  104.   GetViewSettings(VP);
  105.   x:=VP.x2-VP.x1; y:=VP.y2-VP.y1;
  106.   Randomize;
  107.   count:=0;
  108.   repeat
  109.     count:=count+1;
  110.     SetStandartcolor(random(250)+1);
  111.     Arc(random(x),random(y),random(180),random(360),random(100));
  112.     if count=2000 then begin
  113.       clearviewport;
  114.       count:=0;
  115.     end;
  116.   until keypressed;
  117.   readkey;
  118. end;
  119.  
  120. procedure RandomLine;
  121. var VP  : Viewporttype;
  122.     x,y : integer;
  123. begin
  124.   MainWindow('Randomlines');
  125.   GetViewSettings(VP);
  126.   x:=VP.x2-VP.x1+100; y:=VP.y2-VP.y1+100;
  127.   Randomize;
  128.   repeat
  129.     SetStandartcolor(random(250)+1);
  130.     line(random(x)-50,random(y)-50,random(x)-50,random(y)-50);
  131.   until keypressed;
  132.   readkey;
  133. end;
  134.  
  135. procedure Setcolordemo;
  136. var VP      : Viewporttype;
  137.     x,y,i,j : integer;
  138. begin
  139.   MainWindow('SetColordemo');
  140.   GetViewSettings(VP);
  141.   x:=VP.x2-VP.x1; y:=VP.y2-VP.y1;
  142.   for i:=0 to y do
  143.   begin
  144.     j:=(i mod 240)+$10;
  145.     SetColor((j shl 24)+j);
  146.     line(0,i,x,i);
  147.   end;
  148.   readkey;
  149.   { This works only in 256 color modes !!! }
  150.   if GetMaxColor = $FF then begin
  151.     for i:=$10 to $ff do SetColor((i shl 24)+(i shl 8));
  152.     readkey;
  153.     for i:=$10 to $ff do SetColor((i shl 24)+(i shl 16));
  154.     readkey;
  155.     for i:=$10 to $ff do SetColor((i shl 24)+(i shl 16)+(i shl 8)+i);
  156.     readkey;
  157.   end;
  158. end;
  159.  
  160. procedure RandomBars;
  161. var VP  : Viewporttype;
  162.     x,y : integer;
  163.     x1,y1,x2,y2:Integer;
  164. begin
  165.   MainWindow('Randombars');
  166.   GetViewSettings(VP);
  167.   x:=VP.x2-VP.x1; y:=VP.y2-VP.y1;
  168.   Randomize;
  169.   repeat
  170.     SetStandartFillStyle(random(11),random(250)+1);
  171.     x1:=random(x)-50; y1:=random(y)-50;
  172.     x2:=x1+10+random(x shr 1); y2:=y1+10+random(y shr 1);
  173.     Bar(x1,y1,x2,y2);
  174.     Rectangle(x1,y1,x2,y2);
  175.   until keypressed;
  176.   readkey;
  177. end;
  178.  
  179. procedure RandomEllipse;
  180. var VP  : Viewporttype;
  181.     x,y : integer;
  182.     x1,y1,x2,y2:Integer;
  183. begin
  184.   MainWindow('Randomfillellipse');
  185.   GetViewSettings(VP);
  186.   x:=VP.x2-VP.x1; y:=VP.y2-VP.y1;
  187.   Randomize;
  188.   SetLineStyle(1,xorput,1);
  189.   repeat
  190.     SetStandartFillStyle(random(11),random(250)+1);
  191.     x1:=random(x); y1:=random(y);
  192.     x2:=random(100)+20; y2:=random(100)+20;
  193.     FillEllipse(x1,y1,x2,y2);
  194.   until keypressed;
  195.   SetLineStyle(1,normalput,1);
  196.   readkey;
  197. end;
  198.  
  199. {$IFDEF FPK}
  200. procedure RandomTriangle;
  201. var VP    : Viewporttype;
  202.     x,y   : integer;
  203.     a,b,c : Pointtype;
  204. begin
  205.   MainWindow('Randomtriangles');
  206.   GetViewSettings(VP);
  207.   x:=VP.x2 - VP.x1 + 100;
  208.   y:=VP.y2 - VP.y1 + 100;
  209.   Randomize;
  210.   SetLineStyle(1,xorput,1);
  211.   repeat
  212.     SetStandartFillStyle(random(11),random(250)+1);
  213.     a.x:=random(x)-50; a.y:=random(y)-50;
  214.     b.x:=random(x)-50; b.y:=random(y)-50;
  215.     c.x:=random(x)-50; c.y:=random(y)-50;
  216.     FillTriangle(a,b,c);
  217.   until keypressed;
  218.   SetLineStyle(1,normalput,1);
  219.   readkey;
  220. end;
  221. {$ENDIF}
  222.  
  223. begin
  224.   Drive:=ParamStr(0)[1];
  225. {$IFDEF FPK}
  226.   GD:=1;
  227.   GM:=$103;
  228. {$ENDIF}
  229. {$IFDEF TURBO}
  230.   GD := InstallUserDriver('SVGA256',@Dummy);
  231.   GM := 2;
  232. {$ENDIF}
  233.   InitGraph(GD,GM,Drive+':\PP\VESA\CHAR');
  234.   Maxx:=GetMaxX;
  235.   Maxy:=GetMaxY;
  236.   MaxColors:=GetMaxColor;
  237.   RandomDots;
  238.   RandomCircle;
  239.   RandomArc;
  240.   RandomBars;
  241.   RandomEllipse;
  242.   RandomLine;
  243. {$IFDEF FPK}
  244.   RandomTriangle;
  245.   SetColorDemo;
  246. {$ENDIF}
  247.   Closegraph;
  248. end.
  249.